package com.hei.kml.validator;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.Collection;

public interface Validator {
	default void validate(){
		throw new UnsupportedOperationException("Not implemented");
	};

	default boolean notBlank(Object o){
		return StrUtil.isNotBlank(o.toString()) && !o.toString().trim().isEmpty() && (!(o instanceof Collection) || !((Collection<?>) o).isEmpty());
	}

	default boolean inSet(Object o, String[] set){
		return o == null || StrUtil.isBlank(o.toString()) || Arrays.asList(set).contains(o.toString());
	}

	default boolean inScope(Object number, Object min,Object max){
		return number == null || (number instanceof Number
				&& ((Number) number).doubleValue() >= ((Number) min).doubleValue()
				&& ((Number) number).doubleValue() <= ((Number) max).doubleValue());
	}

	default void assert0(boolean b){
		if (!b) {
			throw new IllegalArgumentException();
		}
	}
}
